import allure
import jsonpath
from utils.send_request import send_jdbc_request

@allure.step("3.HTTP响应断言")
def http_assert(case,res):
    if case["check"]:
        # 等于判断
        assert jsonpath.jsonpath(res.json(), case["check"])[0] == case["expected"]
        # 包含判断
    else:
        assert case["expected"] in res.text

def jdbc_assert(case):
    # 核心步骤3；数据库断言--------------------------------------------------------------------
    if case["sql_check"] and case["sql_expected"]:
        with allure.step('3.JDBC响应断言'):
            assert send_jdbc_request(case["sql_check"]) == case["sql_expected"]  # cur.fecth返回的时元组，可以用索引